package com.shinhye.mobilelottery.ui.adapter;

import java.text.DecimalFormat;
import java.util.List;

import com.shinhye.mobilelottery.R;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class PoolAdapter extends BaseAdapter {
	private Context context;
	private int totalNum;
	private List<Integer> selected;
	private int selectRes;
	
	public PoolAdapter(Context context, int number, List<Integer> selected, int selectRes) {
		this.context = context;
		this.totalNum = number;
		this.selected = selected;
		this.selectRes = selectRes;
	}

	@Override
	public int getCount() {
		return totalNum;
	}

	@Override
	public Object getItem(int position) {
		return position + 1;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView tv = new TextView(context);
		tv.setGravity(Gravity.CENTER);
		tv.setTextSize(16);
		DecimalFormat decimalFormat = new DecimalFormat("00");
		tv.setText(decimalFormat.format(position+1));
		if(selected.contains(position))
			tv.setBackgroundResource(selectRes);
		else
			tv.setBackgroundResource(R.drawable.id_defalut_ball);
						
		return tv;
	}

}
